package com.situ.mall.web.service;

import com.mall.common.util.JsonResult;
import com.mall.model.Product;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 商品服务 Feign 客户端
 */
@FeignClient(name = "product-api", path = "/api/products", contextId = "product-api")
public interface ProductFeignService {

    /**
     * 商品详情
     */
    @GetMapping("/{id}")
    JsonResult<Product> getProductById(@PathVariable("id") Long id);

    /**
     * 商品列表查询（分页、搜索、筛选）
     */
    @GetMapping
    JsonResult<Map<String, Object>> getProducts(@RequestParam(value = "keyword", required = false) String keyword,
                                                @RequestParam(value = "brandId", required = false) Long brandId,
                                                @RequestParam(value = "categoryId", required = false) Long categoryId,
                                                @RequestParam(value = "status", required = false) Integer status,
                                                @RequestParam(value = "isHot", required = false) Integer isHot,
                                                @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                @RequestParam(value = "size", defaultValue = "10") Integer size);

    /**
     * 根据品牌ID查询商品
     */
    @GetMapping("/brand/{brandId}")
    JsonResult<List<Product>> getProductsByBrand(@PathVariable("brandId") Long brandId,
                                                 @RequestParam(value = "status", required = false) Integer status);

    /**
     * 根据分类ID查询商品
     */
    @GetMapping("/category/{categoryId}")
    JsonResult<List<Product>> getProductsByCategory(@PathVariable("categoryId") Long categoryId,
                                                    @RequestParam(value = "status", required = false) Integer status);

    /**
     * 扣减库存
     */
    @PostMapping("/{id}/{deductStock}")
    JsonResult<Boolean> deductStock(@PathVariable("id") Long id,
                                    @PathVariable("deductStock") Integer deductStock);
} 